//
//  DingdanliebiaoViewController.m
//  LoveAttention
//
//  Created by 鞠超 on 16/3/10.
//  Copyright © 2016年 JC. All rights reserved.
//

#import "DingdanliebiaoViewController.h"

#import "DataProvider.h"
#import "SVProgressHUD.h"

#import "Dingdan_Model.h"
#import "DingdanList_Model.h"
#import "UIImageView+WebCache.h"
#import "MJRefresh.h"
#import "SearchDingdanViewController.h"
#import "DingdanDetailViewController.h"
@interface DingdanliebiaoViewController () <UITableViewDelegate, UITableViewDataSource , UITextFieldDelegate>

@property (nonatomic, strong) UITableView * tableView;

@property (nonatomic, strong) UITextField * text_search;


//数据
@property (nonatomic, strong) NSMutableArray * arr_all;

@property (nonatomic, strong) NSMutableArray * arr_list;

//页数
@property (nonatomic, assign) NSInteger page;
@end

@implementation DingdanliebiaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(RefreshOrderListWithNotice) name:@"RefreshOrderList" object:nil];
    [self p_data];
    
    [self p_navigationController];
    
    [self p_setupView];
}
-(void)RefreshOrderListWithNotice
{
    [self.tableView.mj_header beginRefreshing];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navigationController
- (void)p_navigationController
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.navigationItem.title = @"订单列表";
    UIButton * btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [btn setBackgroundImage:[UIImage imageNamed:@"返回"] forState:(UIControlStateNormal)];
    btn.frame = CGRectMake(10, 20, 25, 30);
    [btn addTarget:self action:@selector(leftBarButtonItemAction:) forControlEvents:(UIControlEventTouchUpInside)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemSearch) target:self action:@selector(rightBarButtonItemAction:)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
}

//点击事件(左)
- (void)leftBarButtonItemAction:(UIBarButtonItem *)bar
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)rightBarButtonItemAction:(UIBarButtonItem *)bar
{
//    NSLog(@"搜索");
    SearchDingdanViewController * searchDingdanViewController = [[SearchDingdanViewController alloc] init];
    
    [self showViewController:searchDingdanViewController sender:nil];
}

#pragma mark - 布局

- (void)p_setupView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    
    self.tableView.tableFooterView = [[UIView alloc] init];
    
    [self.view addSubview:self.tableView];
    
    __weak __typeof(self) weakSelf = self;
    // 设置回调（一旦进入刷新状态就会调用这个refreshingBlock）
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self p_data];
        
        [weakSelf.tableView reloadData];
        [weakSelf loadNewData];
    }];
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        [self p_data1];
        
        [weakSelf.tableView reloadData];
        [weakSelf loadNewData];
    }];
}

#pragma mark - 数据
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.arr_all.count;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3 + [self.arr_list[section] count];
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger number = [self.arr_list[indexPath.section] count];
    
    if(indexPath.row == 0 || indexPath.row == number + 1 || indexPath.row == number+ 2)
    {
        return 40;
    }
    else
    {
        return 100;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    
    NSInteger number = [self.arr_list[indexPath.section] count];
    
    if(indexPath.row == 0)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH / 2 + 50, 30)];
        name.text = @"订单号";
        
        [cell addSubview:name];
        
        UILabel * type = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 5, 5, SCREEN_WIDTH - CGRectGetMaxX(name.frame) - 10, 30)];
        type.text = @"未付款";
        type.textColor = [UIColor orangeColor];
        type.textAlignment = NSTextAlignmentRight;
        [cell addSubview:type];
        
        if(self.arr_all.count != 0)
        {
            Dingdan_Model * model = self.arr_all[indexPath.section];
            
            name.text = [NSString stringWithFormat:@"订单号:%@",model.ordernum];

            if([model.type integerValue] == 0)
            {
                switch ([model.state integerValue])
                {
                    case 0:
                    {
                        type.text = @"未付款";
                    }
                        break;
                    case 1:
                    {
                        type.text = @"未消费";
                    }
                        break;
                    case 2:
                    {
                        type.text = @"已完成";
                    }
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch ([model.state integerValue])
                {
                    case 0:
                    {
                        type.text = @"未付款";
                    }
                        break;
                    case 1:
                    {
                        type.text = @"已付款";
                    }
                        break;
                    case 2:
                    {
                        type.text = @"已收货";
                    }
                        break;
                    default:
                        break;
                }
            }
        }
    }
    else if(indexPath.row == number + 1)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        
        UILabel * money = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 130, 5, 120, 30)];
        money.text = @"共付 ¥ 100.00";
        money.font = [UIFont systemFontOfSize:15];
        money.textAlignment = NSTextAlignmentRight;
        [cell addSubview:money];
        
//        UILabel * num = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 150 - 130, 5, 150, 30)];
//        num.text = @"共计2件商品";
//        num.font = [UIFont systemFontOfSize:15];
//        num.textAlignment = NSTextAlignmentRight;
//        [cell addSubview:num];
        
        if(self.arr_all.count != 0)
        {
            Dingdan_Model * model = self.arr_all[indexPath.section];

            money.text = [NSString stringWithFormat:@"共付 ¥ %@",model.price];
            cell.textLabel.text=[model.type integerValue]==0?@"到店消费":@"外送";
//            num.text = [NSString stringWithFormat:@"共计%ld件商品",[self.arr_list[indexPath.section] count]];
        }
    }
    else if (indexPath.row == number + 2)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UIButton * btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
        btn.frame = CGRectMake(SCREEN_WIDTH - 90, 5, 80, 30);
        btn.tag = 10000 + indexPath.section;
        btn.backgroundColor = [UIColor orangeColor];
        [btn setTitle:@"订单" forState:(UIControlStateNormal)];
        [btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        
        [btn addTarget:self action:@selector(btnActionDingdan:) forControlEvents:(UIControlEventTouchUpInside)];
        
        
        UIButton * btn1 = [UIButton buttonWithType:(UIButtonTypeSystem)];
        btn1.frame = CGRectMake(SCREEN_WIDTH - 90 - 90, 5, 80, 30);
        btn1.tag = 20000 + indexPath.section;
        btn1.backgroundColor = [UIColor orangeColor];
        [btn1 setTitle:@"订单" forState:(UIControlStateNormal)];
        [btn1 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        
        [btn1 addTarget:self action:@selector(btn1ActionDingdan:) forControlEvents:(UIControlEventTouchUpInside)];
        
        
        [cell addSubview:btn];
        [cell addSubview:btn1];

        if(self.arr_all.count != 0)
        {
            Dingdan_Model * model = self.arr_all[indexPath.section];
            
            if([model.type integerValue] == 0)
            {
                switch ([model.state integerValue])
                {
                    case 0:
                    {
//                        [btn setTitle:@"取消订单" forState:(UIControlStateNormal)];
                        btn.hidden = YES;
                    }
                        break;
                    case 1:
                    {
                        [btn setTitle:@"确认消费" forState:(UIControlStateNormal)];
                        [btn1 setTitle:@"取消订单" forState:(UIControlStateNormal)];
                    }
                        break;
                    case 2:
                    {
//                        [btn setTitle:@"待评价" forState:(UIControlStateNormal)];
                        btn.hidden = YES;

                    }
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch ([model.state integerValue])
                {
                    case 0:
                    {
//                        [btn setTitle:@"取消订单" forState:(UIControlStateNormal)];
                        btn.hidden = YES;
                    }
                        break;
                    case 1:
                    {
//                        NSLog(@"%@",model.delivertytime);
                        if([model.delivertytime length] == 0)
                        {
                            [btn setTitle:@"发货" forState:(UIControlStateNormal)];
                            [btn1 setTitle:@"取消订单" forState:(UIControlStateNormal)];
                        }
                        else
                        {
                            [btn setTitle:@"已发货" forState:(UIControlStateNormal)];
                            [btn1 setTitle:@"取消订单" forState:(UIControlStateNormal)];
                        }
                    }
                        break;
                    case 2:
                    {
                        btn.hidden = YES;
//                        [btn setTitle:@"删除订单" forState:(UIControlStateNormal)];
                    }
                        break;
                    default:
                        break;
                }
            }

        }
    }
    else
    {
        UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
        image.image = [UIImage imageNamed:@"1136-1"];
        [cell addSubview:image];
        
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image.frame) + 10, 10, SCREEN_WIDTH - CGRectGetMaxX(image.frame) - 10 - 70, 30)];
        name.text = @"哈哈哈哈哈哈哈哈哈哈哈哈";
        name.font = [UIFont systemFontOfSize:15];
        [cell addSubview:name];
        
        UILabel * price = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 5, 10, 55, 30)];
        price.text = @"￥200.00";
        price.textAlignment = NSTextAlignmentRight;
        price.font = [UIFont systemFontOfSize:13];
        [cell addSubview:price];
        
        UILabel * num = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 5, CGRectGetMaxY(price.frame), 55, 30)];
        num.text = @"x2";
        num.textAlignment = NSTextAlignmentRight;
        num.font = [UIFont systemFontOfSize:13];
        num.textColor = [UIColor grayColor];
        [cell addSubview:num];
        
        if(self.arr_all.count != 0)
        {
            DingdanList_Model * model = self.arr_list[indexPath.section][indexPath.row - 1];
            NSString *url = [NSString stringWithFormat:@"%@upload/%@",Url,model.imgpath];
            [image sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"1136-1"]];
            
            name.text = [NSString stringWithFormat:@"%@",model.goodsName];
            
            price.text = [NSString stringWithFormat:@"￥ %@",model.price];
            
            num.text = [NSString stringWithFormat:@"x%@",model.quantity];
        }
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSInteger number = [self.arr_list[indexPath.section] count];
    
    if(indexPath.row == 0 || indexPath.row == number + 1 || indexPath.row == number+ 2)
    {
        
    }
    else
    {
        Dingdan_Model * model = self.arr_all[indexPath.section];
        
        DingdanDetailViewController * dingdanDetailViewController = [[DingdanDetailViewController alloc] init];
        
        dingdanDetailViewController.orderid = model.orderid;
        
        [self showViewController:dingdanDetailViewController sender:nil];
    }

    
}


#pragma mark - 点击事件
- (void )btnActionDingdan:(UIButton *)sender
{
    NSInteger index = sender.tag - 10000;
//    NSLog(@"%ld",(long)index);
    Dingdan_Model * model = self.arr_all[index];

    if([[NSString stringWithFormat:@"%@",model.type] isEqualToString:@"0"])
    {//确认订单
        UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"请输入订单验证码" message:@"提示" preferredStyle:(UIAlertControllerStyleAlert)];

        [alert addTextFieldWithConfigurationHandler:^(UITextField *textField){
            textField.placeholder = @"请输入订单确认码";
            textField.clearButtonMode = UITextFieldViewModeWhileEditing;
//                textField.layer.borderColor = [UIColor grayColor].CGColor;
//                textField.layer.borderWidth = 1;
        }];

        UIAlertAction * action_ok = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {

            [self.view endEditing:YES];

            UITextField * textField = alert.textFields.firstObject;
            NSLog(@"%@",textField.text);
            
            DataProvider * dataprovider = [[DataProvider alloc] init];
            NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
            
            [dataprovider setDelegateObject:self setBackFunctionName:@"identifycode:"];
            
            [dataprovider identifycodeWithcode:textField.text merchantid:[defaults objectForKey:@"merchantid"]];
        }];

        UIAlertAction * action_cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
            [self.view endEditing:YES];

        }];
        
        [alert addAction:action_cancel];
        [alert addAction:action_ok];
        
        [self presentViewController:alert animated:YES completion:^{
            
        }];
    }
    else
    {//发货
        
        if([model.delivertytime length] == 0)
        {
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认发货?" preferredStyle:(UIAlertControllerStyleAlert)];
            
            [self presentViewController:alert animated:YES completion:^{
                
            }];
            
            UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                DataProvider * dataprovider = [[DataProvider alloc] init];
                NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
                
                [dataprovider setDelegateObject:self setBackFunctionName:@"mconfirmorder:"];
                
                [dataprovider mconfirmorderWithOrderid:model.orderid opera:@"1" merchanid:[defaults objectForKey:@"merchantid"]];
            }];
            
            [alert addAction:action];
           
        }
        else
        {
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"已经发货" preferredStyle:(UIAlertControllerStyleAlert)];
            
            [self presentViewController:alert animated:YES completion:^{
                
            }];
            
            UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            
            [alert addAction:action];
            
        }
    }
}

- (void )btn1ActionDingdan:(UIButton *)sender
{
    NSInteger index = sender.tag - 20000;
    
    Dingdan_Model * model = self.arr_all[index];
    
    if([[NSString stringWithFormat:@"%@",model.type] isEqualToString:@"0"])
    {
        UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定取消订单?" preferredStyle:(UIAlertControllerStyleAlert)];
        
        [self presentViewController:alert animated:YES completion:^{
            
        }];
        
        UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            DataProvider * dataprovider = [[DataProvider alloc] init];
            NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
            
            [dataprovider setDelegateObject:self setBackFunctionName:@"mconfirmorder:"];
            
            [dataprovider mconfirmorderWithOrderid:model.orderid opera:@"2" merchanid:[defaults objectForKey:@"merchantid"]];
        }];
        
        [alert addAction:action];
        
    }
    else
    {
        if([model.delivertytime length] == 0)
        {
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定取消订单?" preferredStyle:(UIAlertControllerStyleAlert)];
            
            [self presentViewController:alert animated:YES completion:^{
                
            }];
            
            UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                DataProvider * dataprovider = [[DataProvider alloc] init];
                NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
                
                [dataprovider setDelegateObject:self setBackFunctionName:@"mconfirmorder:"];
                
                [dataprovider mconfirmorderWithOrderid:model.orderid opera:@"2" merchanid:[defaults objectForKey:@"merchantid"]];
            }];
            
            [alert addAction:action];
            
        }
        else
        {
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"已经发货,不能取消订单" preferredStyle:(UIAlertControllerStyleAlert)];
            
            [self presentViewController:alert animated:YES completion:^{
                
            }];
            
            UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            
            [alert addAction:action];
        }
    }
    
    
    

}

//
- (void)mconfirmorder:(id )dict
{
//    NSLog(@"%@",dict);
    
    if ([dict[@"status"][@"succeed"] intValue] == 1) {
        @try
        {
            [self p_data];
        }
        @catch (NSException *exception) {
            
        }
        @finally {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                //刷新tableView(记住,要更新放在主线程中)
                
                [self.tableView reloadData];
            });
        }
    }
    else
    {
        [SVProgressHUD showErrorWithStatus:dict[@"status"][@"errdesc"] maskType:SVProgressHUDMaskTypeBlack];
    }
}

//根据确认码确认消费
- (void)identifycode:(id )dict
{
//    NSLog(@"%@",dict);
    
    if ([dict[@"status"][@"succeed"] intValue] == 1) {
        @try
        {
            [SVProgressHUD showSuccessWithStatus:@"消费成功" maskType:(SVProgressHUDMaskTypeBlack)];
            
            [self p_data];
        }
        @catch (NSException *exception) {
            
        }
        @finally {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                //刷新tableView(记住,要更新放在主线程中)
                
                [self.tableView reloadData];
            });
        }
    }
    else
    {
        [SVProgressHUD showErrorWithStatus:dict[@"status"][@"errdesc"] maskType:SVProgressHUDMaskTypeBlack];
    }
}

#pragma mark - 数据
- (void)p_data
{
    self.page = 1;
    
    DataProvider * dataprovider = [[DataProvider alloc] init];
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    
    [dataprovider setDelegateObject:self setBackFunctionName:@"orderlist:"];

    [dataprovider orderlistWith:[defaults objectForKey:@"merchantid"] andpagenumber:@"1" andpagesize:@"10" andordernum:@""];
}

- (void)p_data1
{
    self.page ++;
    
    DataProvider * dataprovider = [[DataProvider alloc] init];
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    
    [dataprovider setDelegateObject:self setBackFunctionName:@"orderlist1:"];
    
    [dataprovider orderlistWith:[defaults objectForKey:@"merchantid"] andpagenumber:[NSString stringWithFormat:@"%ld",(long)self.page] andpagesize:@"10" andordernum:@""];
}

- (void)orderlist:(id )dict
{
    NSLog(@"%@",dict);
    
    if(self.page == 1)
    {
        self.arr_all = nil;
        self.arr_list = nil;
    }
    
    if ([dict[@"status"][@"succeed"] intValue] == 1) {
        @try
        {
            for (NSDictionary * dic in dict[@"data"])
            {
                Dingdan_Model * model = [[Dingdan_Model alloc] init];
                
                [model setValuesForKeysWithDictionary:dic];
                
                [self.arr_all addObject:model];
                
                NSMutableArray * arr= [NSMutableArray array];
                
                for (NSDictionary * dict_list in dic[@"goodlist"])
                {
                    DingdanList_Model * model = [[DingdanList_Model alloc] init];
                    
                    [model setValuesForKeysWithDictionary:dict_list];
                    
                    [arr addObject:model];
                }
                
                [self.arr_list addObject:arr];
            }
        }
        @catch (NSException *exception) {
            
        }
        @finally {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                //刷新tableView(记住,要更新放在主线程中)
                
                [self.tableView reloadData];
            });
        }
    }
    else
    {
        [SVProgressHUD showErrorWithStatus:dict[@"status"][@"errdesc"] maskType:SVProgressHUDMaskTypeBlack];
    }
}


- (void)orderlist1:(id )dict
{
//    NSLog(@"%@",dict);
    
    if ([dict[@"status"][@"succeed"] intValue] == 1) {
        @try
        {
            for (NSDictionary * dic in dict[@"data"])
            {
                Dingdan_Model * model = [[Dingdan_Model alloc] init];
                
                [model setValuesForKeysWithDictionary:dic];
                
                [self.arr_all addObject:model];
                
                NSMutableArray * arr= [NSMutableArray array];
                
                for (NSDictionary * dict_list in dic[@"goodlist"])
                {
                    DingdanList_Model * model = [[DingdanList_Model alloc] init];
                    
                    [model setValuesForKeysWithDictionary:dict_list];
                    
                    [arr addObject:model];
                }
                
                [self.arr_list addObject:arr];
            }
        }
        @catch (NSException *exception) {
            
        }
        @finally {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                //刷新tableView(记住,要更新放在主线程中)
                
                [self.tableView reloadData];
            });
        }
    }
    else
    {
        [SVProgressHUD showErrorWithStatus:dict[@"status"][@"errdesc"] maskType:SVProgressHUDMaskTypeBlack];
    }
}




#pragma mark - 懒加载
- (NSMutableArray *)arr_all
{
    if(_arr_all == nil)
    {
        self.arr_all = [NSMutableArray array];
    }
    
    return _arr_all;
}

- (NSMutableArray *)arr_list
{
    if(_arr_list == nil)
    {
        self.arr_list = [NSMutableArray array];
    }
    
    return _arr_list;
}


#pragma mark - 下拉刷新
- (void)example01
{
    // 马上进入刷新状态
    [self.tableView.mj_header beginRefreshing];
}

-(void)example02
{
    [self.tableView.mj_footer beginRefreshing];
}

- (void)loadNewData
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
    });
    
}

@end
